home *** CD-ROM | disk | FTP | other *** search
/ Mac OS 9 Serial Number Archive / SN Archive 2023.11.04.toast / BSNG / Plugins / TSNG Contributor / CDFinder / CDFinder Plugin ReadMe.c < prev   
Encoding:
Text File  |  1997-12-19  |  26.5 KB  |  450 lines  |  [TEXT/R*ch]

  1. /*
  2. Analyzing CDFinder 2.0's SN# algorithm was _highly entertaining_, the author has obviously seen C&N or some such lists entry for CDFinder and has added distributed
  3. checks (except for a minor mistake -- documented with correction below) for the pirate user names "NASA" and "MoonDark".  What was especially entertaining
  4. is how predictable this guy thinks, appart from the naming conventions I bet the following source code is 99.8% _exactly the same_ as the authors.  The
  5. birthdate, authors initials and "PV" = "Pirated Version" insights were bonuses, but the icing on the cake was the logic error in the "MoonDark" test.  I
  6. don't even use the program in question, but as soon as soon as I saw the check code I could see it was interesting so I just had to reverse engineer it.  
  7. I hope everyone gets a kick out of this -- MoonDark, especially, should find this funny.  Enclosed at the end is the 68K assembly source dump so you can 
  8. see what I'm describing first hand.
  9. */
  10.  
  11. //A5 Globals - these are checked and/or used after by the main registration logic.
  12.  
  13. UInt16    globA5Minus0x0DD6 = 0;    //global that is set to its correct value of 0x07AE iff chars 2,5,9, and 10 of snStr[] are the correct digits
  14. UInt32    globA5Minus0x0DD4;        //holds final nameStr hash value
  15. UInt16    globA5Minus0x0DD0 = 0;    //global that is set to its correct value of 0x0007 iff chars 1 and 7 of snStr[] are correct [note this is the authors (Norbert Doerner) initials]
  16. UInt16    globA5Minus0x0DCE = 0;    //global that is set to its correct value of 0x000D iff chars 3,4,6, and 8 of snStr[] are the correct digits
  17.  
  18. //notice the magic correct numbers uniquely define the date 1966/07/13, which is almost undoubtedly the author's (or his girlfriend's) birthdate.
  19.  
  20. //this is a more or less direct translation of the assembly code.
  21. //when combined with the assembly source below is a very good tutorial/example to learn from, especially for those that have difficulty following
  22. //intricate sequences of integer math operations.
  23. //the following returns 1 iff a pirate user name was used, otherwise it returns 0 - it also does almost all the work of validating a serial number
  24. UInt16    Check1CDFinder2SN(Str255 nameStr, Str15 snStr);
  25. UInt16    Check1CDFinder2SN(Str255 nameStr, Str15 snStr)
  26. {
  27. UInt32        d3 = 1;                //flag indicating pirate user name "\pMoonDark" (actually the author made an error in the source code that checks for "oo" in "MoonDark", see below for explanation)
  28. UInt32        d4 = 1;                //flag indicating pirate user name "\pNASA"
  29. SInt32        d5;
  30. UInt32        d7 = 0;
  31. UInt32        d6 = (UInt8) nameStr[0];
  32. SInt32        u, v, w, d7;
  33. Str255        xStr;
  34.  
  35.     globA5Minus0x0DCE = 0;
  36.     if (nameStr[0] == 0) return 0;
  37.     if (nameStr[0] != 4) d4 = 0;
  38.     if (nameStr[0] != 8) d3 = 0;
  39.  
  40.     for (d5 = d6; d5 > 0 ; d5--)                                        //this loop calculates a partial hash of the nameStr
  41.     {
  42.         u    = 7UL * (UInt32) (d5 * 17L);                                //note the UInt32 multiply
  43.         v    = (SInt16) ((u / 13L) * 831L);                                //note the SInt16 sign extend
  44.         w    = ((v * (v + 4097L)) / 83L) * 137L;            
  45.         d7 += (((SInt16) v / (SInt16) w) + u) * (UInt8) nameStr[d5];    //note the SInt16 divide then extend
  46.  
  47.     }
  48.     if ((nameStr[8] != 'k') && (d3 != 0)) d3 = 0;            //note: the last part of the conditional expression is unecessary
  49.     if ((nameStr[2] != nameStr[4]) && (d4 != 0)) d4 = 0;    //note: the last part of the conditional expression is unecessary
  50.     d5 = d7 * 53L;
  51.     
  52.     //the following code should be present here, but due to a parenthesization/logic error in the authors code it is always false and thus never executed
  53.     //if (((nameStr[2] != nameStr[3]) || (nameStr[2] != 'o')) && (d3 != 0)) d3 = 0;    //note: the last part of the conditional expression is unecessary
  54.  
  55.     //in actuality the author wrote something like this:
  56.     //if (((nameStr[2] != nameStr[3]) == 'o') && (d3 != 0)) d3 = 0;
  57.     //of course the == 'o' condition is always false, thus any user name of the form "M**nDark", where '*' is any character, is in fact also illegal.
  58.     
  59.     if ((nameStr[4] != 'A') && (d4 != 0)) d4 = 0;            //note: the last part of the conditional expression is unecessary
  60.     NumToString(d5 * 7L, xStr);
  61.     globA5Minus0x0DD4 = d5 * 7L;
  62.     if ((nameStr[3] != 'S') && (d4 != 0)) d4 = 0;            //note: the last part of the conditional expression is unecessary
  63.     d6 = xStr[0];
  64.     
  65.     if ((nameStr[1] != 'M') && (d3 != 0)) d3 = 0;            //note: the last part of the conditional expression is unecessary
  66.     if (snStr[0] != 10) return 1;
  67.     if ((nameStr[1] != 'N') && (d4 != 0)) d4 = 0;            //note: the last part of the conditional expression is unecessary
  68.     if (xStr[0] < 8)                                        //extend the hashed string to at least 8 chars in a nonstandard way
  69.     {
  70.         for (d5 = xStr[0] + 1; d5 <= 8; d5++) xStr[d5] = xStr[1];
  71.         xStr[0] = 8;
  72.     }
  73.     
  74.     if ((nameStr[4] != 'n') && (d3 != 0)) d3 = 0;            //note: the last part of the conditional expression is unecessary
  75.     if (d4 != 0)            //note that at this point (d4 != 0) implies that nameStr[] = "\pNASA"
  76.     {
  77.         xStr[5]        = 'P';    //no doubt this stands for "Pirated Version"
  78.         snStr[7]    = 'V';
  79.         return 1;            //pirate name was used
  80.     }
  81.     if ((nameStr[5] != 'D') && (d3 != 0)) d3 = 0;            //note: the last part of the conditional expression is unecessary
  82.     if (snStr[ 2] != xStr[5]) goto LB1;
  83.     if (snStr[ 9] != xStr[2]) goto LB1;
  84.     if (snStr[ 5] != xStr[7]) goto LB1;
  85.     if (snStr[10] != xStr[6]) goto LB1;
  86.     globA5Minus0x0DD6 = 0x07AE;        //chars 2,5,9, and 10 of snStr[] are the correct digits
  87. LB1:
  88.     if ((nameStr[7] != 'r') && (d3 != 0)) d3 = 0;            //note: the last part of the conditional expression is unecessary
  89.     if (snStr[7] != 'D') goto LB2;                    //Doerner
  90.     if (snStr[1] != 'N') goto LB2;                    //Norbert
  91.     globA5Minus0x0DD0 = 0x0007;        //chars 1 and 7 of snStr[] are correct [note this is the authors (Norbert Doerner) initials]
  92. LB2:
  93.     if ((nameStr[6] != 'a') && (d3 != 0)) d3 = 0;            //note: the last part of the conditional expression is unecessary
  94.     if (snStr[ 4] != xStr[4]) goto LB3;
  95.     if (snStr[ 6] != xStr[3]) goto LB3;
  96.     if (snStr[ 8] != xStr[1]) goto LB3;
  97.     if (snStr[ 3] != xStr[8]) goto LB3;
  98.     globA5Minus0x0DCE = 0x000D;        //chars 3,4,6, and 8 of snStr[] are the correct digits
  99. LB3:    
  100.     if (d3 != 0)            //note that at this point (d3 != 0) implies that nameStr[] = "\pM**nDark"
  101.     {
  102.         xStr[5]        = 'P';    //no doubt this stands for "Pirated Version"
  103.         snStr[7]    = 'V';
  104.         return 1;            //pirate name was used
  105.     }
  106.     if (d4 != 0) return d4;    //the author was unsure of himself and added this extraneous check (d4 is always zero here)
  107.     return 0;    //pirate name was not used
  108. }
  109.  
  110. //The following is a 68K assembly dump of the authors code corresponding to the above
  111. /*
  112. +08C1A 0527837A   LINK       A6,#$FFC0                               
  113. +08C1E 0527837E   MOVEM.L    D3-D7/A2/A3,-(A7)                       
  114. +08C22 05278382   MOVEA.L    $0008(A6),A2                            
  115. +08C26 05278386   MOVEA.L    $000C(A6),A3                            
  116. +08C2A 0527838A   MOVEQ      #$01,D4                                 
  117. +08C2C 0527838C   MOVEQ      #$00,D6                                 
  118. +08C2E 0527838E   MOVE.B     (A2),D6                                 
  119. +08C30 05278390   CLR.W      -$0DCE(A5)                              
  120. +08C34 05278394   TST.B      (A2)                                    
  121. +08C36 05278396   BNE.S      'CODE 0001 25…urces'+08C3E ; 0527839E   
  122. +08C38 05278398   MOVEQ      #$00,D0                                 
  123. +08C3A 0527839A   BRA        'CODE 0001 25…urces'+08E1E ; 0527857E   
  124. +08C3E 0527839E   MOVEQ      #$01,D3                                 
  125. +08C40 052783A0   MOVEQ      #$00,D7                                 
  126. +08C42 052783A2   MOVEQ      #$04,D0                                 
  127. +08C44 052783A4   CMP.L      D0,D6                                   
  128. +08C46 052783A6   BEQ.S      'CODE 0001 25…urces'+08C4A ; 052783AA   
  129. +08C48 052783A8   MOVEQ      #$00,D4                                 
  130. +08C4A 052783AA   MOVEQ      #$08,D0                                 
  131. +08C4C 052783AC   CMP.L      D0,D6                                   
  132. +08C4E 052783AE   BEQ.S      'CODE 0001 25…urces'+08C52 ; 052783B2   
  133. +08C50 052783B0   MOVEQ      #$00,D3                                 
  134. +08C52 052783B2   MOVE.L     D6,D5                                   
  135. +08C54 052783B4   BRA.S      'CODE 0001 25…urces'+08C76 ; 052783D6   
  136. +08C56 052783B6      //contents of this math loop are given below - it is quit interesting actually
  137. +08C72 052783D2   SUBQ.L     #$1,D5                                  
  138. +08C74 052783D4   ADDQ.W     #$4,A7                                  
  139. +08C76 052783D6   TST.L      D5                                      
  140. +08C78 052783D8   BGT.S      'CODE 0001 25…urces'+08C56 ; 052783B6   
  141. +08C7A 052783DA   CMPI.B     #$6B,$0008(A2)             ; 'k'        
  142. +08C80 052783E0   BEQ.S      'CODE 0001 25…urces'+08C88 ; 052783E8   
  143. +08C82 052783E2   TST.L      D3                                      
  144. +08C84 052783E4   BEQ.S      'CODE 0001 25…urces'+08C88 ; 052783E8   
  145. +08C86 052783E6   MOVEQ      #$00,D3                                 
  146. +08C88 052783E8   MOVE.B     $0002(A2),D0                            
  147. +08C8C 052783EC   CMP.B      $0004(A2),D0                            
  148. +08C90 052783F0   BEQ.S      'CODE 0001 25…urces'+08C98 ; 052783F8   
  149. +08C92 052783F2   TST.L      D4                                      
  150. +08C94 052783F4   BEQ.S      'CODE 0001 25…urces'+08C98 ; 052783F8   
  151. +08C96 052783F6   MOVEQ      #$00,D4                                 
  152. +08C98 052783F8   MOVEQ      #$35,D5                    ; '5'        
  153. +08C9A 052783FA   MULS.L     D7,D5                                   
  154. +08C9E 052783FE   MOVE.B     $0002(A2),D0                            
  155. +08CA2 05278402   CMP.B      $0003(A2),D0                            
  156. +08CA6 05278406   SEQ        D0                                      //• this is where the "MoonDark" logic error is
  157. +08CA8 05278408   NEG.B      D0                                      //• this is where the "MoonDark" logic error is
  158. +08CAA 0527840A   CMPI.B     #$6F,D0                    ; 'o'        
  159. +08CAE 0527840E   BNE.S      'CODE 0001 25…urces'+08CB6 ; 05278416   
  160. +08CB0 05278410   TST.L      D3                                      
  161. +08CB2 05278412   BEQ.S      'CODE 0001 25…urces'+08CB6 ; 05278416   
  162. +08CB4 05278414   MOVEQ      #$00,D3                                 
  163. +08CB6 05278416   CMPI.B     #$41,$0004(A2)             ; 'A'        
  164. +08CBC 0527841C   BEQ.S      'CODE 0001 25…urces'+08CC4 ; 05278424   
  165. +08CBE 0527841E   TST.L      D4                                      
  166. +08CC0 05278420   BEQ.S      'CODE 0001 25…urces'+08CC4 ; 05278424   
  167. +08CC2 05278422   MOVEQ      #$00,D4                                 
  168. +08CC4 05278424   MOVEQ      #$07,D0                                 
  169. +08CC6 05278426   MULS.L     D5,D0                                   
  170. +08CCA 0527842A   MOVE.L     D0,-(A7)                                
  171. +08CCC 0527842C   PEA        -$0040(A6)                              
  172. +08CD0 05278430   JSR        'CODE 0003 25…aries'+023D6              //this is just a NumToString call
  173. +08CD6 05278436   MOVEQ      #$07,D0                                 
  174. +08CD8 05278438   MULS.L     D5,D0                                   
  175. +08CDC 0527843C   MOVE.L     D0,-$0DD4(A5)                           
  176. +08CE0 05278440   CMPI.B     #$53,$0003(A2)             ; 'S'        
  177. +08CE6 05278446   BEQ.S      'CODE 0001 25…urces'+08CEE ; 0527844E   
  178. +08CE8 05278448   TST.L      D4                                      
  179. +08CEA 0527844A   BEQ.S      'CODE 0001 25…urces'+08CEE ; 0527844E   
  180. +08CEC 0527844C   MOVEQ      #$00,D4                                 
  181. +08CEE 0527844E   MOVEQ      #$00,D6                                 
  182. +08CF0 05278450   MOVE.B     -$0040(A6),D6                           
  183. +08CF4 05278454   CMPI.B     #$4D,$0001(A2)             ; 'M'        
  184. +08CFA 0527845A   BEQ.S      'CODE 0001 25…urces'+08D02 ; 05278462   
  185. +08CFC 0527845C   TST.L      D3                                      
  186. +08CFE 0527845E   BEQ.S      'CODE 0001 25…urces'+08D02 ; 05278462   
  187. +08D00 05278460   MOVEQ      #$00,D3                                 
  188. +08D02 05278462   CMPI.B     #$0A,(A3)                               
  189. +08D06 05278466   BEQ.S      'CODE 0001 25…urces'+08D0E ; 0527846E   
  190. +08D08 05278468   MOVEQ      #$01,D0                                 
  191. +08D0A 0527846A   BRA        'CODE 0001 25…urces'+08E1E ; 0527857E   
  192. +08D0E 0527846E   CMPI.B     #$4E,$0001(A2)             ; 'N'        
  193. +08D14 05278474   BEQ.S      'CODE 0001 25…urces'+08D1C ; 0527847C   
  194. +08D16 05278476   TST.L      D4                                      
  195. +08D18 05278478   BEQ.S      'CODE 0001 25…urces'+08D1C ; 0527847C   
  196. +08D1A 0527847A   MOVEQ      #$00,D4                                 
  197. +08D1C 0527847C   MOVEQ      #$08,D0                                 
  198. +08D1E 0527847E   CMP.L      D0,D6                                   
  199. +08D20 05278480   BGE.S      'CODE 0001 25…urces'+08D40 ; 052784A0   
  200. +08D22 05278482   MOVE.B     #$08,-$0040(A6)                         
  201. +08D28 05278488   MOVE.L     D6,D5                                   
  202. +08D2A 0527848A   ADDQ.L     #$1,D5                                  
  203. +08D2C 0527848C   BRA.S      'CODE 0001 25…urces'+08D3A ; 0527849A   
  204. +08D2E 0527848E   LEA        -$0040(A6),A0                           
  205. +08D32 05278492   MOVE.B     -$003F(A6),$00(A0,D5.L)                 
  206. +08D38 05278498   ADDQ.L     #$1,D5                                  
  207. +08D3A 0527849A   MOVEQ      #$08,D0                                 
  208. +08D3C 0527849C   CMP.L      D0,D5                                   
  209. +08D3E 0527849E   BLE.S      'CODE 0001 25…urces'+08D2E ; 0527848E   
  210. +08D40 052784A0   CMPI.B     #$6E,$0004(A2)             ; 'n'        
  211. +08D46 052784A6   BEQ.S      'CODE 0001 25…urces'+08D4E ; 052784AE   
  212. +08D48 052784A8   TST.L      D3                                      
  213. +08D4A 052784AA   BEQ.S      'CODE 0001 25…urces'+08D4E ; 052784AE   
  214. +08D4C 052784AC   MOVEQ      #$00,D3                                 
  215. +08D4E 052784AE   TST.L      D4                                      
  216. +08D50 052784B0   BEQ.S      'CODE 0001 25…urces'+08D64 ; 052784C4   
  217. +08D52 052784B2   MOVE.B     #$50,-$003B(A6)            ; 'P'        
  218. +08D58 052784B8   MOVE.B     #$56,$0007(A3)             ; 'V'        
  219. +08D5E 052784BE   MOVEQ      #$01,D0                                 
  220. +08D60 052784C0   BRA        'CODE 0001 25…urces'+08E1E ; 0527857E   
  221. +08D64 052784C4   CMPI.B     #$44,$0005(A2)             ; 'D'        
  222. +08D6A 052784CA   BEQ.S      'CODE 0001 25…urces'+08D72 ; 052784D2   
  223. +08D6C 052784CC   TST.L      D3                                      
  224. +08D6E 052784CE   BEQ.S      'CODE 0001 25…urces'+08D72 ; 052784D2   
  225. +08D70 052784D0   MOVEQ      #$00,D3                                 
  226. +08D72 052784D2   MOVE.B     -$003B(A6),D0                           
  227. +08D76 052784D6   CMP.B      $0002(A3),D0                            
  228. +08D7A 052784DA   BNE.S      'CODE 0001 25…urces'+08DA0 ; 05278500   
  229. +08D7C 052784DC   MOVE.B     -$003E(A6),D0                           
  230. +08D80 052784E0   CMP.B      $0009(A3),D0                            
  231. +08D84 052784E4   BNE.S      'CODE 0001 25…urces'+08DA0 ; 05278500   
  232. +08D86 052784E6   MOVE.B     -$0039(A6),D0                           
  233. +08D8A 052784EA   CMP.B      $0005(A3),D0                            
  234. +08D8E 052784EE   BNE.S      'CODE 0001 25…urces'+08DA0 ; 05278500   
  235. +08D90 052784F0   MOVE.B     -$003A(A6),D0                           
  236. +08D94 052784F4   CMP.B      $000A(A3),D0                            
  237. +08D98 052784F8   BNE.S      'CODE 0001 25…urces'+08DA0 ; 05278500   
  238. +08D9A 052784FA   MOVE.W     #$07AE,-$0DD6(A5)                       
  239. +08DA0 05278500   CMPI.B     #$72,$0007(A2)             ; 'r'        
  240. +08DA6 05278506   BEQ.S      'CODE 0001 25…urces'+08DAE ; 0527850E   
  241. +08DA8 05278508   TST.L      D3                                      
  242. +08DAA 0527850A   BEQ.S      'CODE 0001 25…urces'+08DAE ; 0527850E   
  243. +08DAC 0527850C   MOVEQ      #$00,D3                                 
  244. +08DAE 0527850E   CMPI.B     #$44,$0007(A3)             ; 'D'        
  245. +08DB4 05278514   BNE.S      'CODE 0001 25…urces'+08DC4 ; 05278524   
  246. +08DB6 05278516   CMPI.B     #$4E,$0001(A3)             ; 'N'        
  247. +08DBC 0527851C   BNE.S      'CODE 0001 25…urces'+08DC4 ; 05278524   
  248. +08DBE 0527851E   MOVE.W     #$0007,-$0DD0(A5)                       
  249. +08DC4 05278524   CMPI.B     #$61,$0006(A2)             ; 'a'        
  250. +08DCA 0527852A   BEQ.S      'CODE 0001 25…urces'+08DD2 ; 05278532   
  251. +08DCC 0527852C   TST.L      D3                                      
  252. +08DCE 0527852E   BEQ.S      'CODE 0001 25…urces'+08DD2 ; 05278532   
  253. +08DD0 05278530   MOVEQ      #$00,D3                                 
  254. +08DD2 05278532   MOVE.B     -$003C(A6),D0                           
  255. +08DD6 05278536   CMP.B      $0004(A3),D0                            
  256. +08DDA 0527853A   BNE.S      'CODE 0001 25…urces'+08E00 ; 05278560   
  257. +08DDC 0527853C   MOVE.B     -$003D(A6),D0                           
  258. +08DE0 05278540   CMP.B      $0006(A3),D0                            
  259. +08DE4 05278544   BNE.S      'CODE 0001 25…urces'+08E00 ; 05278560   
  260. +08DE6 05278546   MOVE.B     -$003F(A6),D0                           
  261. +08DEA 0527854A   CMP.B      $0008(A3),D0                            
  262. +08DEE 0527854E   BNE.S      'CODE 0001 25…urces'+08E00 ; 05278560   
  263. +08DF0 05278550   MOVE.B     -$0038(A6),D0                           
  264. +08DF4 05278554   CMP.B      $0003(A3),D0                            
  265. +08DF8 05278558   BNE.S      'CODE 0001 25…urces'+08E00 ; 05278560   
  266. +08DFA 0527855A   MOVE.W     #$000D,-$0DCE(A5)                       
  267. +08E00 05278560   TST.L      D3                                      
  268. +08E02 05278562   BEQ.S      'CODE 0001 25…urces'+08E14 ; 05278574   
  269. +08E04 05278564   MOVE.B     #$50,-$003B(A6)            ; 'P'        
  270. +08E0A 0527856A   MOVE.B     #$56,$0007(A3)             ; 'V'        
  271. +08E10 05278570   MOVEQ      #$01,D0                                 
  272. +08E12 05278572   BRA.S      'CODE 0001 25…urces'+08E1E ; 0527857E   
  273. +08E14 05278574   TST.L      D4                                      
  274. +08E16 05278576   BEQ.S      'CODE 0001 25…urces'+08E1C ; 0527857C   
  275. +08E18 05278578   MOVE.B     D4,D0                                   
  276. +08E1A 0527857A   BRA.S      'CODE 0001 25…urces'+08E1E ; 0527857E   
  277. +08E1C 0527857C   MOVEQ      #$00,D0                                 
  278. +08E1E 0527857E   MOVEM.L    (A7)+,D3-D7/A2/A3                       
  279. +08E22 05278582   UNLK       A6                                      
  280. +08E24 05278584   RTS                                                
  281.  
  282. //Math contained inside the 'Math loop', note code is linear with no branching
  283. //thus you may read top to bottom as if the jsr/bsr are not there
  284. //ie. I have traced thru and listed the code in the order it executes.
  285. //notice that there is some very subtle type changing going on…
  286. //specifically almost all the math is signed long, but watch out for the
  287. //exceptions -- they are critical
  288.  
  289. +08C56 053405D6   MOVEQ      #$11,D0                                 
  290. +08C58 053405D8   MULS.L     D5,D0                                   
  291. +08C5C 053405DC   MOVE.L     D0,-(A7)                                
  292.  
  293. +08C5E 053405DE   BSR.L      'CODE 0001 25…urces'+08E26 ; 053407A6   
  294.  
  295. +08E26 053407A6   LINK       A6,#$FFFC                               
  296. +08E2A 053407AA   MOVE.L     D3,-(A7)                                
  297. +08E2C 053407AC   MOVEQ      #$07,D3                                 
  298. +08E2E 053407AE   MULU.L     $0008(A6),D3                            //••• exception
  299. +08E34 053407B4   MOVE.L     D3,D0                                   
  300. +08E36 053407B6   DIVS.L     #$0000000D,D0                           
  301. +08E3E 053407BE   MULS.L     #$0000033F,D0                           
  302. +08E46 053407C6   MOVE.L     D0,-$0004(A6)                           
  303. +08E4A 053407CA   MOVE.W     -$0002(A6),-(A7)                        
  304. +08E4E 053407CE   MOVE.L     D3,-(A7)                                
  305. +08E50 053407D0   JSR        'CODE 0001 25…urces'+08BBC ; 0534053C   
  306.  
  307. +08BBC 0534053C   LINK       A6,#$0000                               
  308. +08BC0 05340540   MOVE.W     $000C(A6),-(A7)                         
  309. +08BC4 05340544   BSR.L      'CODE 0001 25…urces'+08BDE ; 0534055E   
  310.  
  311. +08BDE 0534055E   LINK       A6,#$FFFC                               
  312. +08BE2 05340562   MOVE.L     D5,-(A7)                                
  313. +08BE4 05340564   MOVE.W     $0008(A6),D5                            
  314. +08BE8 05340568   MOVEQ      #$53,D2                    ; 'S'        
  315. +08BEA 0534056A   MOVEA.W    D5,A0                                   //••• exception, sign extension is implicit here
  316. +08BEC 0534056C   MOVE.L     A0,D1                                   
  317. +08BEE 0534056E   ADDI.L     #$00001001,D1                           
  318. +08BF4 05340574   MOVE.L     D1,D0                                   
  319. +08BF6 05340576   ADD.L      A0,D0                                   
  320. +08BF8 05340578   MOVE.L     D0,-$0004(A6)                           
  321. +08BFC 0534057C   MOVE.L     A0,D0                                   
  322. +08BFE 0534057E   MULS.L     D1,D0                                   
  323. +08C02 05340582   DIVS.L     D2,D0                                   
  324. +08C06 05340586   MOVE.L     D0,D2                                   
  325. +08C08 05340588   MOVE.L     #$00000089,D1                           
  326. +08C0E 0534058E   MOVE.L     D1,D0                                   
  327. +08C10 05340590   MULS.L     D2,D0                                   
  328. +08C14 05340594   MOVE.L     (A7)+,D5                                
  329. +08C16 05340596   UNLK       A6                                      
  330. +08C18 05340598   RTS                                                
  331.  
  332. +08BCA 0534054A   MOVEA.W    $000C(A6),A0                            
  333. +08BCE 0534054E   MOVE.L     A0,D1                                   
  334. +08BD0 05340550   DIVS.W     D0,D1                                   //••• exception
  335. +08BD2 05340552   EXT.L      D1                                      
  336. +08BD4 05340554   ADD.L      $0008(A6),D1                            
  337. +08BD8 05340558   MOVE.W     D1,D0                                   
  338. +08BDA 0534055A   UNLK       A6                                      
  339. +08BDC 0534055C   RTS                                                
  340.  
  341. +08E54 053407D4   EXT.L      D0                                      
  342. +08E56 053407D6   ADDQ.W     #$6,A7                                  
  343. +08E58 053407D8   MOVE.L     (A7)+,D3                                
  344. +08E5A 053407DA   UNLK       A6                                      
  345. +08E5C 053407DC   RTS                                                
  346.  
  347. +08C64 053405E4   MOVEQ      #$00,D1                                 
  348. +08C66 053405E6   MOVE.B     $00(A2,D5.L),D1                         
  349. +08C6A 053405EA   EXT.L      D1                                      
  350. +08C6C 053405EC   MULS.L     D0,D1                                   
  351. +08C70 053405F0   ADD.L      D1,D7                                   
  352.  
  353.  
  354. //this is the main registration logic that calls the above
  355. 'CODE 0001 25D4 Sources'
  356. +089F2 05278152   PEA        -$0084(A6)                              
  357. +089F6 05278156   PEA        -$0044(A6)                              
  358. +089FA 0527815A   BSR.L      'CODE 0001 25…urces'+08C1A ; 0527837A   //call the checking routine
  359. +08A00 05278160   SUBQ.B     #$1,D0                                  
  360. +08A02 05278162   ADDQ.W     #$8,A7                                  
  361. +08A04 05278164   BNE.S      'CODE 0001 25…urces'+08A1E ; 0527817E   //will branch if user name was ok
  362. +08A06 05278166   CLR.W      -$0DD0(A5)                              
  363. +08A0A 0527816A   MOVE.W     #$FFFF,-$0DCE(A5)                       
  364. +08A10 05278170   BSR.L      'CODE 0001 25…urces'+08A76 ; 052781D6   
  365. +08A16 05278176   MOVE.W     #$000B,-$0DD6(A5)                       
  366. +08A1C 0527817C   MOVEQ      #$01,D5                                 
  367. +08A1E 0527817E   CMPI.W     #$0007,-$0DD0(A5)                      //check for correct magic globals combination starts here
  368. +08A24 05278184   BEQ.S      'CODE 0001 25…urces'+08A2E ; 0527818E   
  369. +08A26 05278186   CMPI.W     #$000D,-$0DCE(A5)                       
  370. +08A2C 0527818C   BNE.S      'CODE 0001 25…urces'+08A38 ; 05278198   
  371. +08A2E 0527818E   CMPI.W     #$07AE,-$0DD6(A5)                       
  372. +08A34 05278194   BNE.S      'CODE 0001 25…urces'+08A38 ; 05278198   
  373. +08A36 05278196   MOVEQ      #$01,D4                                 
  374. +08A38 05278198   TST.B      D4                                      
  375. +08A3A 0527819A   BNE.S      'CODE 0001 25…urces'+08A4C ; 052781AC   
  376. +08A3C 0527819C   TST.B      D5                                      
  377. +08A3E 0527819E   BNE.S      'CODE 0001 25…urces'+08A4C ; 052781AC   
  378. +08A40 052781A0   MOVE.W     #$0002,-(A7)                            
  379. +08A44 052781A4   BSR.L      'CODE 0001 25…urces'+00CC0 ; 05270420   
  380. +08A4A 052781AA   ADDQ.W     #$2,A7                                  
  381. +08A4C 052781AC   TST.B      D4                                      
  382. +08A4E 052781AE   BEQ        'CODE 0001 25…urces'+0892C ; 0527808C   
  383. +08A52 052781B2   PEA        -$0084(A6)                              
  384. +08A56 052781B6   PEA        -$0044(A6)                              
  385. +08A5A 052781BA   BSR.L      'CODE 0001 25…urces'+06560 ; 05275CC0   
  386. +08A60 052781C0   MOVE.W     #$0001,-(A7)                            
  387. +08A64 052781C4   BSR.L      'CODE 0001 25…urces'+00CC0 ; 05270420   
  388. +08A6A 052781CA   LEA        $000A(A7),A7                            
  389. +08A6E 052781CE   MOVEM.L    (A7)+,D3-D5                             
  390. +08A72 052781D2   UNLK       A6                                      
  391. +08A74 052781D4   RTS                                                
  392. */
  393.  
  394.  
  395. //this is needed for the generator, which is below
  396. static Boolean myEqualPStrWithWildcardPStr(const Str255 s, const Str255 t);
  397. static Boolean myEqualPStrWithWildcardPStr(const Str255 s, const Str255 t)
  398. {
  399. UInt8    *p = (UInt8 *) s;
  400. UInt8    *q = (UInt8 *) t;
  401. UInt8    *r = &p[p[0] + 1];
  402.  
  403.     if (*(p++) != *(q++)) return FALSE;
  404.     if (p != r) while (((*p == *q) || (*q == '*')) && (++p != r)) ++q;
  405.     return (Boolean) (p == r);
  406. }
  407.  
  408.  
  409. static void Generate1CDFinder2SN(const Str255 nameStr, Str15 snStr);
  410. static void Generate1CDFinder2SN(const Str255 nameStr, Str15 snStr)
  411. {
  412. SInt32        len = (UInt8) nameStr[0];
  413. SInt32        i, u, v, w, x    = 0;
  414. Str15        xStr;
  415.  
  416.  
  417.     if ((len == 0) || myEqualPStr(nameStr, "\pNASA") || myEqualPStrWithWildcardPStr(nameStr, "\pM**nDark"))
  418.     {
  419.         snStr[0] = 0;
  420.         return;
  421.     }
  422.     for (i = len; i > 0 ; i--)
  423.     {
  424.         u = 7UL * (UInt32) (i * 17L);                                //note the UInt32 multiply
  425.         v = (SInt16) ((u / 13L) * 831L);                            //note the SInt16 sign extend
  426.         w = ((v * (v + 4097L)) / 83L) * 137L;            
  427.         x+= (((SInt16) v / (SInt16) w) + u) * (UInt8) nameStr[i];    //note the SInt16 divide then extend
  428.     }
  429.     x*= 53L;
  430.     x*=  7L;
  431.     NumToString(x, xStr);
  432.     if (xStr[0] < 8)            //extend xStr to 8 chars in a nonstandard way
  433.     {
  434.         for (i = xStr[0] + 1; i <= 8; i++) xStr[i] = xStr[1];
  435.         xStr[0] = 8;
  436.     }    
  437.     snStr[ 0] = 10;
  438.     snStr[ 1] = 'N';                    //Norbert
  439.     snStr[ 2] = xStr[5];
  440.     snStr[ 3] = xStr[8];
  441.     snStr[ 4] = xStr[4];
  442.     snStr[ 5] = xStr[7];
  443.     snStr[ 6] = xStr[3];
  444.     snStr[ 7] = 'D';                    //Doerner
  445.     snStr[ 8] = xStr[1];
  446.     snStr[ 9] = xStr[2];
  447.     snStr[10] = xStr[6];
  448. }
  449.  
  450.